import pygame
import os

import UAI

from Box    import Box
from Person import Person

class Level:
    
    def __init__(self, filename):
        fullname = os.path.join('data', 'levels', filename + '.lvl')
        file = open(fullname)
        self.file = []
        for line in file:
            self.file.append(line)
    
    def load(self):
        for y, line in enumerate(self.file):
            for x, item in enumerate(line):
                self.populate((x, y), item)
    
    def populate(self, (x,y), item):
        pos = (x * 40 + 20, y * 40 + 20)
        if item == 'B':
            UAI.game.addItem(Box(pos))
        elif item == '1':
            UAI.game.addItem(Person(pos, '1', (255,  0,  0)))
        elif item == '2':
            UAI.game.addItem(Person(pos, '2', (0  ,  0,255)))
                